package logic

import (
	"context"
	"errors"
	"person/models/mysql"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserShowLogic) UserShow(in *personrpc.UserShowRequest) (*personrpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.User

	if err := user.FindUserByUserId(mysql.DB, in.UserId); err != nil {
		return nil, errors.New("用户不存在")
	}

	user.UserShow(mysql.DB, in.UserId)

	return &personrpc.UserShowResponse{
		Account:   user.Account,
		Password:  user.Password,
		Username:  user.Username,
		Marriage:  user.Marriage,
		CardImage: user.CardImage,
		Card:      user.Card,
		Sex:       user.Sex,
		Birth:     user.Birth,
		Phone:     user.Phone,
	}, nil
}
